levelsBundledOutput = {}
levelsBundledOutput[0] = {
	top=colors.yellow + colors.orange + colors.red,
	right=colors.white + colors.yellow + colors.orange + colors.red
	}
levelsBundledOutput[1] = {
	top=colors.orange + colors.red,
	right=colors.white + colors.yellow + colors.orange + colors.red
	}
levelsBundledOutput[2] = {
	top=0,
	right=colors.white + colors.yellow + colors.orange + colors.red
	}
levelsBundledOutput[3] = {
	top=0,
	right=colors.orange + colors.red
	}
levelsBundledOutput[4] = {
	top=0,
	right=0
	}

	
local level = 4
ELEVATOR_CHANNEL = 1

modem = peripheral.wrap("left")	
modem.open(ELEVATOR_CHANNEL)

redstone.setBundledOutput("top", levelsBundledOutput[level]["top"])
redstone.setBundledOutput("right", levelsBundledOutput[level]["right"])

while true do
	event, param1, param2, param3, param4, param5 = os.pullEvent()
	
	if event == "key" then
		print("level=" .. level)
		if param1 == 200 then
			print("Up")
			if level < 4 then
				level = level + 1
			end
		elseif param1 == 208 then
			print("Down")
			if level > 0 then
				level = level - 1
			end
		end
		redstone.setBundledOutput("top", levelsBundledOutput[level]["top"])
		redstone.setBundledOutput("right", levelsBundledOutput[level]["right"])
	elseif event == "modem_message" then
		local new_level = tonumber(param4)
		if 0 <= new_level and new_level <= 4 then
			level = new_level
			print(level)
			redstone.setBundledOutput("top", levelsBundledOutput[level]["top"])
			redstone.setBundledOutput("right", levelsBundledOutput[level]["right"])
		end

--	else
--		print("unknown event: " .. event)
	end
end

modem.close(ELEVATOR_CHANNEL)